package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.LpsFlService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.LpsFlForm;
import com.youlai.boot.system.model.query.LpsFlQuery;
import com.youlai.boot.system.model.vo.LpsFlVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 订单分类前端控制层
 *
 * @author lwb
 * @since 2025-07-16 21:51
 */
@Tag(name = "订单分类接口")
@RestController
@RequestMapping("/api/v1/lpsFls")
@RequiredArgsConstructor
public class LpsFlController  {

    private final LpsFlService lpsFlService;

    @Operation(summary = "订单分类分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:lpsFl:query')")
    public PageResult<LpsFlVO> getLpsFlPage(LpsFlQuery queryParams ) {
        IPage<LpsFlVO> result = lpsFlService.getLpsFlPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增订单分类")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:lpsFl:add')")
    public Result<Void> saveLpsFl(@RequestBody @Valid LpsFlForm formData ) {
        boolean result = lpsFlService.saveLpsFl(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取订单分类表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:lpsFl:edit')")
    public Result<LpsFlForm> getLpsFlForm(
        @Parameter(description = "订单分类ID") @PathVariable Long id
    ) {
        LpsFlForm formData = lpsFlService.getLpsFlFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改订单分类")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:lpsFl:edit')")
    public Result<Void> updateLpsFl(
            @Parameter(description = "订单分类ID") @PathVariable Long id,
            @RequestBody @Validated LpsFlForm formData
    ) {
        boolean result = lpsFlService.updateLpsFl(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除订单分类")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:lpsFl:delete')")
    public Result<Void> deleteLpsFls(
        @Parameter(description = "订单分类ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lpsFlService.deleteLpsFls(ids);
        return Result.judge(result);
    }
}
